// Toolbar.h : Declaration of the CToolbar

#pragma once
#include "resource.h"       // main symbols

#include "Microformats_i.h"
#include <shlguid.h>
#include <exdispid.h>
#include <mshtmdid.h>
#include <fstream>
#include <iostream>
#include <string>

using namespace std;

#if defined(_WIN32_WCE) && !defined(_CE_DCOM) && !defined(_CE_ALLOW_SINGLE_THREADED_OBJECTS_IN_MTA)
#error "Single-threaded COM objects are not properly supported on Windows CE platform, such as the Windows Mobile platforms that do not include full DCOM support. Define _CE_ALLOW_SINGLE_THREADED_OBJECTS_IN_MTA to force ATL to support creating single-thread COM object's and allow use of it's single-threaded COM object implementations. The threading model in your rgs file was set to 'Free' as that is the only threading model supported in non DCOM Windows CE platforms."
#endif



// CToolbar

class ATL_NO_VTABLE CToolbar :
	public CComObjectRootEx<CComSingleThreadModel>,
	public CComCoClass<CToolbar, &CLSID_Toolbar>,
	public IObjectWithSiteImpl<CToolbar>,
	public IDispatchImpl<IToolbar, &IID_IToolbar, &LIBID_MicroformatsLib, /*wMajor =*/ 1, /*wMinor =*/ 0>,
	public IDispEventImpl<1, CToolbar, &DIID_DWebBrowserEvents2, &LIBID_SHDocVw, 1, 1>, 
	public IDispEventImpl<2, CToolbar, &DIID_HTMLDocumentEvents2, &LIBID_MSHTML, 4, 0>
{
public:
	typedef IDispEventImpl<1, CToolbar, &DIID_DWebBrowserEvents2, &LIBID_SHDocVw, 1, 1> ISinkBrowserEvents;
	typedef IDispEventImpl<2, CToolbar, &DIID_HTMLDocumentEvents2, &LIBID_MSHTML, 4, 0> ISinkDocEvents;

	CToolbar()
	{
	}

DECLARE_REGISTRY_RESOURCEID(IDR_TOOLBAR)

DECLARE_NOT_AGGREGATABLE(CToolbar)

BEGIN_COM_MAP(CToolbar)
	COM_INTERFACE_ENTRY(IToolbar)
	COM_INTERFACE_ENTRY(IDispatch)
	COM_INTERFACE_ENTRY(IObjectWithSite)
END_COM_MAP()

	DECLARE_PROTECT_FINAL_CONSTRUCT()

	HRESULT FinalConstruct()
	{
		return S_OK;
	}

	void FinalRelease()
	{
	}

public:
	STDMETHOD (SetSite) (IUnknown *pUnkSite);

BEGIN_SINK_MAP(CToolbar)
	SINK_ENTRY_EX(1, DIID_DWebBrowserEvents2, DISPID_DOCUMENTCOMPLETE, OnDocumentComplete)
	SINK_ENTRY_EX(2, DIID_HTMLDocumentEvents2, DISPID_READYSTATECHANGE, OnReadyStateChange)
END_SINK_MAP()

	void STDMETHODCALLTYPE OnDocumentComplete(IDispatch *pDisp, VARIANT *pvarURL);
	void STDMETHODCALLTYPE OnReadyStateChange(IHTMLEventObj *eventObj);
	HRESULT STDMETHODCALLTYPE CToolbar::InjectScriptTags(IDispatch *pDoc);
	void STDMETHODCALLTYPE CToolbar::InjectTag(IDispatch *pDoc, IHTMLDOMNode *parent, CComBSTR tagName, CComBSTR attrName, CComVariant attrValue);
	BOOL STDMETHODCALLTYPE CToolbar::TagExists(IHTMLDOMNode *parent, CComBSTR tagName, CComBSTR attrName, CComVariant attrValue);

private:
	CComPtr<IWebBrowser2> m_spWebBrowser;
	CComQIPtr<IHTMLDocument2> m_spDocument;

	BOOL m_fAdvised;
	BOOL m_fDocAdvised;

};

OBJECT_ENTRY_AUTO(__uuidof(Toolbar), CToolbar)
